<template>
  <div>
    <el-form ref="myform" :model="formItem" :rules="rules" label-width="100px" size="mini">
      <el-row :gutter="40">
        <el-col :span="12">
          <el-form-item label="操作" prop="operation">
            <el-radio v-for="(item) in operation" :key="item.value" v-model="formItem.operation" :label="item.value">{{ item.label }}</el-radio>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="40">
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="formItem.remark" placeholder="请输入备注" type="textarea" :rows="3" :autosize="true" resize="none" />
          </el-form-item>
        </el-col>
      </el-row>
      <div style="text-align: right;">
        <el-form-item>
          <el-button type="primary" @click="ok('submit')">提交</el-button>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>

<script>
import {
  create
} from '@neu/dcom-ui/api/changeConfirmation'
const formItem = {
  operation: 'pass',
  remark: '',
  workOrderNum: '',
  taskId: ''
}
export default {
  name: 'ChangeConfirmation',
  components: {},
  props: {
    taskId: {
      required: false,
      type: String,
      default: 'NULL'
    },
    workOrderNum: {
      required: false,
      type: String,
      default: ''
    }
  },
  data() {
    return {
      operation: [
        { value: 'pass', label: '确认' },
        { value: 'serviceDesk', label: '转服务台' },
        { value: 'reject', label: '驳回' }
      ],
      /** 是否显示用户选择对话框 */
      userSelDialogFormVisible: false,
      // 编辑的表单内容
      formItem: {
        ...formItem
      },
      // 表单验证规则
      rules: {
        executor: [{
          required: true,
          message: '执行人不能为空',
          trigger: 'change'
        }]
      }
    }
  },
  watch: {},
  created() {},
  methods: {
    ok(value) {
      return new Promise(resolve => {
        this.$refs.myform.validate((valid) => {
          if (valid) {
            this.formItem.workOrderNum = this.workOrderNum
            this.formItem.taskId = this.taskId
            create(this.formItem).then(res => {
              if (res.status === 'success') {
                this.$emit('cancelNewOrderForm', 'refresh')
              }
            })
          } else {
            resolve(false)
          }
        })
      })
    },
    reset() {
      this.$refs.myform.resetFields()
      this.formItem = { ...formItem }
    },
    /** 选择用户按钮 */
    handleUserIconClick() {
      this.userSelDialogFormVisible = true
    }
  }
}
</script>
